package com.xm.xmapp.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.xm.xmapp.R;

public class SubmitBankInfoDialog extends Dialog {
	private Context context;
	private OnSubmitBankInfoDialog onDaKeHuDialog;
	private boolean isHaveBank = true;

	public void setOnSubmitBankInfoDialog(OnSubmitBankInfoDialog submitBankInfoDialog) {
		this.onDaKeHuDialog = submitBankInfoDialog;
	
	}

	public interface OnSubmitBankInfoDialog {
		void accept();

		void refuse();
	}

	public SubmitBankInfoDialog(Context context, boolean isHaveBank) {
		super(context, R.style.Dialog);
		this.context = context;
		this.isHaveBank = isHaveBank;
	}

	@SuppressLint("InflateParams")
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.dialog_submitbankinfo, null);
		TextView tv_text = (TextView) view.findViewById(R.id.tv_text);
		if(!isHaveBank) {
			tv_text.setText("确认押金退还?");
		}
		setContentView(view);
		view.findViewById(R.id.accept).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();
				if (onDaKeHuDialog != null) {
					onDaKeHuDialog.accept();
				}
			}
		});

		view.findViewById(R.id.refuse).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();
				if (onDaKeHuDialog != null) {
					onDaKeHuDialog.refuse();
				}
			}
		});

		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
		lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
		dialogWindow.setAttributes(lp);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		init();
	}
}
